#!/bin/bash

# Install nvm dependencies
echo "# Installing nvm dependencies"
# apt-get -y install build-essential libssl-dev
apt-get install -y python gcc make g++
# Execute nvm installation script
echo "# Executing nvm installation script"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

# Set up nvm environment without restarting the shell
export NVM_DIR="${HOME}/.nvm"
[ -s "${NVM_DIR}/nvm.sh" ] && . "${NVM_DIR}/nvm.sh"
[ -s "${NVM_DIR}/bash_completion" ] && . "${NVM_DIR}/bash_completion"

# config nvm mirrors
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node

echo "# Installing nodeJS"
nvm install --lts

# Configure nvm to use version 8.9.2
nvm use --lts
nvm alias default 'lts/*'

# config npm

# registry=https://registry.npm.taobao.org/
# disturl=https://npm.taobao.org/dist
# electron_mirror=https://npm.taobao.org/mirrors/electron/
# sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
# phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
npm config set registry https://registry.npm.taobao.org/
npm config set disturl https://npm.taobao.org/dist
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/

# Install the latest version of npm
# echo "# Installing npm"
# npm install npm@latest -g